package com.mvvmhabit.org.binding.viewadapter.recycleview

import androidx.databinding.BindingAdapter
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.RecyclerView

/**
 * @Date: 2021/1/19 14:10
 * @Author:小妖
 * @Description: 添加或删除默认动画
 */
@BindingAdapter(value = ["isItemAnimator"], requireAll = false)
fun setCustomItemAnimator(recyclerView: RecyclerView, isItemAnimator: Boolean) {
    if (isItemAnimator) {
        recyclerView.itemAnimator = DefaultItemAnimator()
    }
}

/**
 * 分割线
 */
@BindingAdapter(value = ["itemDecoration"])
fun setDividerItemDecoration(
    recyclerView: RecyclerView,
    itemDecoration: RecyclerView.ItemDecoration
) {
    recyclerView.addItemDecoration(itemDecoration)
}